<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>工单统计-满意度</title>
</head>
<body>
	<div class="layui-container">
		<div class="layui-form" lay-filter="order-form">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">处理人</label>
					<div class="layui-input-inline">
						<input type="text" name="handler" id="handler" placeholder="请输入处理人"
							autocomplete="off" class="layui-input">
					</div>
				</div>
				
				<div class="layui-inline">
					<label class="layui-form-label">所属办事处</label>
					<div class="layui-input-inline">
						<input type="text" name="area" id="area" placeholder="请输入所属办事处"
							autocomplete="off" class="layui-input">
					</div>
				</div>
				</div>
				
				<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">时间范围</label>
					<div class="layui-input-inline" style="width: 140px;">
						<input type="text" class="layui-input" id="startDate" name="startDate">
					</div>
					<div class="layui-form-mid">-</div>
					<div class="layui-input-inline" style="width: 140px;">
						<input type="text" class="layui-input" id="endDate" name="endDate">
					</div>
				</div>
				<div class="layui-inline">
					<button class="layui-btn layuiadmin-btn-list" lay-submit="" lay-filter="order-search">
						<i class="layui-icon layui-icon-search"></i>
					</button>
				</div>
				<div class="layui-inline">
					<button class="layui-btn layuiadmin-btn-list" id="export-peopleOrder">导出EXCEL</button>
				</div>

			</div>
		</div>
	</div>
	<table class="layui-hide" id="ordersTable" lay-filter="ordersTable"></table>
	<script type="text/javascript">
		var table = layui.table;
		var form = layui.form;
		form.render();
		
		function checkDate(startTime,endTime){              
            if(startTime.length>0 && endTime.length>0){     
                var startTmp=startTime.split("-");  
                var endTmp=endTime.split("-");  
                var sd=new Date(startTmp[0],startTmp[1],startTmp[2]);  
                var ed=new Date(endTmp[0],endTmp[1],endTmp[2]);  
                if(sd.getTime()>ed.getTime()){   
                    return false;     
                }     
            }     
            return true;     
        }   
		
		form.on('submit(order-search)', function(data){
			var creator='';
			var handler='';
			var area='';
			var status = 0;
			var startDate='';
			var endDate='';
			
			creator = data.field.creator;
			handler = data.field.handler;
			area = data.field.area;
			status = data.field.status;
			startDate = data.field.startDate;
			endDate = data.field.endDate;
			
			if(!checkDate(startDate,endDate)){
				layer.msg('开始时间不能大于结束时间！');
				return;
			}
			
			orderTableNs.reload({
				where:{
					creator:creator,
					handler:handler,
					area:area,
					status:status,
					startDate:startDate,
					endDate:endDate
				},
				page:{
					curr:1
				}
			});
			return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
		});
		
		//导出数据
		$('#export-peopleOrder').on('click',function(){
			layer.load(3);
			var handler = $("#handler").val();
			var area = $("#area").val();
			var startDate = $("#startDate").val();
			var endDate = $("#endDate").val();
			
			$.ajax({
				url:window.basePath+'/report/ExportExcelBySatisfactionOrder',
				headers: {"token" : window.token},
				method: "post",
				dataType:'json',
				data: {
					handler: handler,
					area: area,
					startDate: startDate,
					endDate: endDate
				},
				success:function(data){
					layer.closeAll("loading");
					 if(data.success === true){
						 window.open(data.obj);
					 }
					 layer.msg(data.message);
				},
				error:function(){
					layer.closeAll("loading"); 
				}
			});
		});
		
		var orderTableNs = table.render({
			elem : '#ordersTable',
			height : 'full-220',
			url : window.basePath + '/report/findAllSatisfactionReoprt',
			headers: {"token" : window.token},
			method: "post",
			cols : [ [ {
				field : 'handle',
				width : 100,
				align:'center',
				title : '处理人'
			}, {
				field : 'handleNo',
				width : 100,
				align:'center',
				title : '工号'
			}, {
				field : 'area',
				width : 200,
				align:'center',
				title : '所属办事处'
			}, {
				field : 'sumHours',
				width : 150,
				align:'center',
				title : '回复工单总工时',
                templet:function(data){
                    return fixed(data.sumHours);
                }
			}, {
				field : 'sumOrders',
				title : '回复工单总数',
				align:'center',
				width : 150,
			}, {
				field : 'satisfaction',
				title : '客户满意度',
				align:'center',
				width : 100,
                templet:function(data){
            return data.satisfaction * 100 + "%";
        }
			} ] ],
			text : {
				none : '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
			},
			page : true
		});

        function fixed(str) {
            if (!str) str = '0.0';
            var ret = Math.round(parseFloat(str) * 100) / 100;
            var decimal = ret.toString().split('.');
            if (decimal.length === 1) {
                return ret.toString() + '.0'
            };
            if (decimal.length > 1) {
                if (decimal[1].length < 1) {
                    return ret.toString() + '0'
                }
                return ret
            };
            return ret;
        }
		var laydate = layui.laydate;

		//执行一个laydate实例
		laydate.render({
			elem : '#startDate' //指定元素
		});
		laydate.render({
			elem : '#endDate' //指定元素
		});
	</script>

</body>
</html>